package com.woniuxy.light_smart.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.light_smart.dto.LightPoleDto;
import com.woniuxy.light_smart.service.FacilityService;
import com.woniuxy.light_smart.service.LightPoleService;
import com.woniuxy.light_smart.util.Result;
import com.woniuxy.light_smart.vo.LightPoleVo;
import com.woniuxy.light_smart.vo.PointVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("lights")
public class LightController {
    @Autowired
    private LightPoleService lightPoleService;
    @Autowired
    private FacilityService facilityService;



    @PostMapping("query")
    public Result getAll(@RequestBody LightPoleDto lightPoleDto){
        PageHelper.startPage(lightPoleDto.getCurrentPage(), lightPoleDto.getPageSize());
        List<LightPoleVo> all = facilityService.getAllState(lightPoleService.selByNameAndArea(lightPoleDto));
        PageInfo<LightPoleVo> pageInfo=new PageInfo(all);
        return Result.ok().data("lightList",all).data("total",pageInfo.getTotal());
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable String id){
        lightPoleService.del(id);
        return Result.ok();
    }

    @GetMapping("")
    public Result getPoint(){
        List<LightPoleVo> pointVos = lightPoleService.selXy();
        return Result.ok().data("pointList",pointVos);
    }

}
